import { createRouter, createWebHashHistory } from 'vue-router'
import { store } from 'xijs';
import { pageConstant } from '@/config/contant.js'

const routes = [
    {
        path: '/',
        redirect: '/login',
        children: [{
            name: 'login',
            path: '/login',
            meta: {
                title: '登录'
            },
            component: () => import('@/views/other/login.vue'),
        }]
    },
    {
        path: '/home',
        component: () => import('@/views/home.vue'),
        name: 'home',
        meta: {
            title: '首页'
        },
    },
    {
        name: 'fangkeyuyue',
        path: '/fangkeyuyue',
        meta: {
            title: '访客预约'
        },
        component: () => import('@/views/other/fangkeyuyue.vue'),
    },
    {
        name: 'communityInfo',
        path: '/communityInfo',
        meta: {
            title: '小区信息'
        },
        component: () => import('@/views/houseCommunity/communityInfo.vue'),
    },
    {
        name: 'zhouBianPeiTao',
        path: '/zhouBianPeiTao',
        meta: {
            title: '周边配套'
        },
        component: () => import('@/views/houseCommunity/zhouBianPeiTao.vue'),
    },
    {
        name: 'gongGongSheShi',
        path: '/gongGongSheShi',
        meta: {
            title: '公共设施'
        },
        component: () => import('@/views/houseCommunity/gongGongSheShi.vue'),
    },
    {
        name: 'communityQuanJing',
        path: '/communityQuanJing',
        meta: {
            title: '小区全景'
        },
        component: () => import('@/views/houseCommunity/communityQuanJing.vue'),
    },
    {
        name: 'myApartmentType',
        path: '/myApartmentType',
        meta: {
            title: '我的户型'
        },
        component: () => import('@/views/digitalDeliveryHouse/myApartmentType.vue'),
    },
    {
        name: 'houseInfo',
        path: '/houseInfo',
        meta: {
            title: '房屋信息'
        },
        component: () => import('@/views/digitalDeliveryHouse/houseInfo.vue'),
    },
    {
        name: 'storeInfo',
        path: '/storeInfo',
        meta: {
            title: '商铺信息'
        },
        component: () => import('@/views/digitalDeliveryHouse/storeInfo.vue'),
    },
    {
        name:'storeContract',
        path:'/storeContract',
        meta:{
            title:'商铺合同'
        },
        component:()=>import('@/views/digitalDeliveryHouse/storeContract.vue'),
    },
    {
        name: 'houseHeTong',
        path: '/houseHeTong',
        meta: {
            title: '房屋合同'
        },
        component: () => import('@/views/digitalDeliveryHouse/houseHeTong.vue'),
    },
    {
        name: 'bimTuZhi',
        path: '/bimTuZhi',
        meta: {
            title: 'BIM图纸'
        },
        component: () => import('@/views/digitalDeliveryHouse/bimTuZhi.vue'),
    },
    {
        name: 'jiaoFuYangBan',
        path: '/jiaoFuYangBan',
        meta: {
            title: '交付样板'
        },
        component: () => import('@/views/digitalDeliveryHouse/jiaoFuYangBan.vue'),
    },
    {
        name: 'fireSafe',
        path: '/fireSafe',
        meta: {
            title: '消防安全'
        },
        component: () => import('@/views/digitalDeliveryHouse/fireSafe.vue'),
    },
    {
        name: 'AIchat',
        path: '/AIchat',
        meta: {
            title: 'AI问答'
        },
        component: () => import('@/views/digitalDeliveryHouse/AIchat.vue'),
    },
    {
        name: 'kongQiJianCe',
        path: '/kongQiJianCe',
        meta: {
            title: '空气监测'
        },
        component: () => import('@/views/digitalDeliveryHouse/kongQiJianCe.vue'),
    },
    {
        name: 'louPanZiXun',
        path: '/louPanZiXun',
        meta: {
            title: '楼盘资讯'
        },
        component: () => import('@/views/digitalDeliveryHouse/louPanZiXun.vue'),
    },
    {
        name: 'jingZhuangYangBan',
        path: '/jingZhuangYangBan',
        meta: {
            title: '精装样板'
        },
        component: () => import('@/views/digitalViewHouse/jingZhuangYangBan.vue'),
    },
    {
        name: 'apartmentType',
        path: '/apartmentType',
        meta: {
            title: '小区户型'
        },
        component: () => import('@/views/digitalViewHouse/apartmentType.vue'),
    },
    {
        name: 'kanFangYuYue',
        path: '/kanFangYuYue',
        meta: {
            title: '看房预约'
        },
        component: () => import('@/views/digitalViewHouse/kanFangYuYue.vue'),
    },
    {
        name: 'wenJuanDiaoCha',
        path: '/wenJuanDiaoCha',
        meta: {
            title: '问卷调查'
        },
        component: () => import('@/views/digitalViewHouse/wenJuanDiaoCha.vue'),
    },
    {
        name: 'businessInsight',
        path: '/businessInsight',
        meta: {
            title: '商业洞察'
        },
        component: () => import('@/views/digitalDeliveryHouse/businessInsight.vue'),
    },
    {
        name:'storePhotos',
        path:'/storePhotos',
        meta:{
            title:'商铺实拍'
        },
        component:()=>import('@/views/digitalDeliveryHouse/storePhotos.vue'),
    },
    {
        name:'supportingFacilities',
        path:'/supportingFacilities',
        meta:{
            title:'配套设施'
        },
        component:()=>import('@/views/digitalDeliveryHouse/supportingFacilities.vue'),
    },
    {
        name:'storeLocation',
        path:'/storeLocation',
        meta:{
            title:'商铺位置'
        },
        component:()=>import('@/views/digitalDeliveryHouse/storeLocation.vue'),
    },
    {
        name: 'storeVR',
        path: '/storeVR',
        meta: {
            title: 'VR全景'
        },
        component: () => import('@/views/digitalDeliveryHouse/storeVR.vue'),
    }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    const app = document.getElementById('app')
    if (app) {
      app.scrollTo(0, 0)
    }

    return { x: 0, y: 0 }
  }
})

// 导航守卫
router.beforeEach((to, from, next) => {
    if (store.get(pageConstant.storageSyncUserKey).status == 0) {
        // 已登录且要跳转的页面是登录页
        if (to.path === '/login') {
            next({ path: '/home' })
        } else {
            next()
        }
    } else {
        if (to.path === '/login') {
            next()
        } else {
            // 否则全部重定向到登录页
            next('/login')
        }
    }
})

export default router
